package oli.plugpack.core
{
	import oli.plugpack.errors.PlugError;
	import oli.plugpack.services.PlugService;

	public final class PlugContext
	{
		private var _plugin:PlugIn;
		
		public function PlugContext(plug:PlugIn)
		{
			_plugin = plug;
		}
		public function get plugin():PlugIn
		{
			return _plugin;
		}
		public function get allServices():Vector.<PlugService>
		{
			return _plugin.services;
		}
		public function getService(fullyQualifiedName:String):PlugService
		{
			var services:Vector.<PlugService> = _plugin.services;
			var ps:PlugService;
			for each(var _ps:PlugService in services)
			{
				if (_ps.id == fullyQualifiedName)
				{
					ps = _ps;
					break;
				}
			}
			if(ps != null)
			{
				return ps;
			}
			else
			{
				throw new PlugError('A PlugService named ' + fullyQualifiedName + ' could not be found. Check spelling and make sure \n' + 
						'you provided a fully qualified class name (meaning package declaration and class name combined. For example, \n' + 
						'a class "MyClass" in the package "com.example.test" becomes : "com.example.test.MyClass"). \n');
			}
		}
	}
}